package model

import (
	"blog2021/configs"
	"blog2021/tools/logger"

	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

const (
	MaxPageCount      = 12
	ProfileCount      = 250
	ShowHotCount      = 8
	LastCommentsCount = 20
	MaxJokeCount      = 30
	MaxCommentsCount  = 1000
	MaxBingPageCount  = 9
)

var (
	db      *gorm.DB
	GatherC *Gather
)

func init() {
	logger.Info("model init start")
	defer logger.Info("model init end")

	db_, err := gorm.Open("mysql", configs.Instance().Mysql.Uri)
	if err != nil {
		panic(err)
	}

	db = db_
	if !db.HasTable(AccessLog{}) {
		if err := db.CreateTable(AccessLog{}).Error; err != nil {
			logger.Error("create AccessLog table failed,", err)
		}
	}
	InitHtmlTags()

	GatherC = new(Gather)
	if err := GatherC.Init(); err != nil {
		panic(err)
	}
}
